package com.example.project_dish.Order;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.project_dish.Capital.Comment;
import com.example.project_dish.R;

import java.util.List;

public class AdapterOrder extends BaseAdapter {
    Context context;
    List<OrderEvent> data;
    private ListView listView;
    private TextView order_none;


    public AdapterOrder(Context context, List<OrderEvent> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if(view == null){
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.order_list,null);
            holder.dishes_name = (TextView) view.findViewById(R.id.dishesName);
            holder.ImageId = (ImageView) view.findViewById(R.id.dishesImage);
            holder.dishes_price = (TextView) view.findViewById(R.id.dishesPrice);
            holder.dishes_comment = (TextView) view.findViewById(R.id.dishesComment);
            holder.reduce = (ImageView) view.findViewById(R.id.dishesReduce);
            view.setTag(holder);
        }else {
            holder = (ViewHolder) view.getTag();
        }
        holder.dishes_name.setText(data.get(i).getName());
        holder.ImageId.setImageResource(data.get(i).getId());
        holder.dishes_price.setText(data.get(i).getPrice());
        holder.dishes_comment.setText(data.get(i).getComment());
        holder.reduce.setImageResource(data.get(i).getReduce());
        holder.reduce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                data.remove(data.get(i));
                notifyDataSetChanged();
            }
        });
        return view;
    }

    public void addComment(OrderEvent comment){
        data.add(comment);
        notifyDataSetChanged();
    }
    public static class ViewHolder{
        private TextView dishes_name;
        private TextView dishes_price;
        private TextView dishes_comment;
        private ImageView ImageId;
        private ImageView reduce;
    }
}
